package com.example.roomworldsample;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class NewWordActivity extends AppCompatActivity implements View.OnClickListener {

    public static final String EXTRA_REPLY = "com.example.roomworldsample";
    private EditText editWord;
    private Button buttonSave;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_word);

        editWord = (EditText) findViewById(R.id.edit_word);
        buttonSave = (Button) findViewById(R.id.button_save);
        buttonSave.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        Intent intent = new Intent(NewWordActivity.this, MainActivity.class);
        if (TextUtils.isEmpty(editWord.getText())) {
            setResult(Activity.RESULT_CANCELED, intent);
        } else {
            String word = editWord.getText().toString();
            intent.putExtra(EXTRA_REPLY, word);
            setResult(Activity.RESULT_OK, intent);
        }
        finish();
    }
}